<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="top-box flexWrap">
					<view class="screen-box">
						<view class="nav-box flexWrapNo">
							<view class="nav-item" :class="{active:currmentIndex==0}" @tap="changeNav(0)">日</view>
							<view class="nav-item" :class="{active:currmentIndex==1}" @tap="changeNav(1)">月</view>
							<!-- <view class="nav-item" :class="{active:currmentIndex==2}" @tap="changeNav(2)">年</view> -->
						</view>
						<view class="date-box flexWrapNo" @tap="showDate()">
							<image src="/static/index/calendar.png" class="calendar-icon"></image>
							{{starTime}}～{{endTime}}
						</view>
					</view>
					<view class="memberData-img">
						<image src="/static/index/operatingData.png"></image>
					</view>
				</view>
				<!-- 日 -->
				<view class="date-boxs" v-if="dateFlag">
					<view class="date-title">时间筛选</view>
					<view class="date-cont flexWrap">
						<view class="screen-item flexWrap">
							<picker mode="date" :data-index='0' :value="starTime" @change="bindDateChange"
								:start="startViewTime" :end="date" :fields="fields">
								<view class="select-input">{{starTime}}</view>
							</picker>
							<text class="triangle"></text>
						</view>
						<view class="screen-item flexWrap">
							<picker mode="date" :data-index='1' :value="date" @change="bindDateChange" :start="starTime"
								:end="date" :fields="fields">
								<view class="select-input">{{endTime}}</view>
							</picker>
							<text class="triangle"></text>
						</view>
					</view>
					<view class="determine-btn flexWrapNo">
						<!-- <view @tap="reSet()">重置</view> -->
						<view class="determine" @tap="submit()">确认</view>
					</view>
				</view>
				<view class="mask-wrap" v-if="dateFlag" @tap="closeDate()"></view>
				<view class="profit-box-new">
					<view class="flexWrap">
						<view>
							<text v-if="isup()&&currmentIndex==1"
								class="start-time">开始日期:{{$tools.formatDate(coming_time,'day')}}</text>
						</view>
						<view class="describe-box flexWrapNo" @tap="describeFlag=true">
							<image src="/static/index/describe-icon.png" class="describe-icon"></image>
							报表说明
						</view>
					</view>
					<view class="profit-top flexWrap">
						<view class="profit-item flexWarpCenterColumn">
							<view>{{operatingData.order_count||'0.00'}}</view>
							<view class="profit-text">已结算订单数</view>
						</view>
						<view class="profit-item flexWarpCenterColumn">
							<view>{{operatingData.tatal_income||'0.00'}}</view>
							<view class="profit-text">总收入</view>
						</view>
						<view class="profit-item flexWarpCenterColumn">
							<view>{{operatingData.cashout_amount||'0.00'}}</view>
							<view class="profit-text">已结算金额</view>
						</view>
					</view>
					<view class="profit-cont">
						<view class="profit-title-box flexWrap">
							<view>小程序收入</view>
							<view>{{operatingData.program_income||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>微信支付平台</view>
							<view>{{operatingData.order_online_amount||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>门店卡充值</view>
							<view>{{operatingData.recharge_money||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>通卡抵扣开台</view>
							<view>{{operatingData.card_amount||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>助教订单</view>
							<view>{{operatingData.assistant_amount||'0.00'}}</view>
						</view>
						<view class="line"></view>
						<view class="profit-item flexWrap">
							<view>小程序退款</view>
							<view>{{operatingData.refund_money||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>小程序系统服务费</view>
							<view>{{operatingData.program_platform_commission||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>银行手续费</view>
							<view>{{operatingData.bank_amount||'0.00'}}</view>
						</view>
					</view>
					<view class="profit-cont">
						<view class="profit-title-box flexWrap">
							<view>团单收入</view>
							<view>
								{{(Number(operatingData.tuan_amount)+Number(operatingData.douyin_amount)).toFixed(2)||'0.00'}}
							</view>
						</view>
						<view class="profit-item flexWrap">
							<view>美团核销</view>
							<view>{{operatingData.tuan_amount||'0.00'}}</view>
						</view>
						<view class="profit-item flexWrap">
							<view>抖音核销</view>
							<view>{{operatingData.douyin_amount||'0.00'}}</view>
						</view>
						<view class="line"></view>
						<view class="profit-item flexWrap">
							<view>团单系统服务费（次日补扣）</view>
							<view>{{operatingData.day_platform_commission||'0.00'}}</view>
						</view>
					</view>
					<view class="profit-cont">
						<view class="profit-title-box flexWrap">
							<view>补扣团单系统服务费</view>
							<view class="profit-title-right flexWarpColumn"
								@tap="goPage('/page-home/deductionList?starTime='+starTime+'&endTime='+endTime)">
								{{operatingData.entry_platform_commission||'0.00'}}
								<text class="look" v-if="operatingData.entry_platform_commission">查看明细</text>
							</view>
						</view>
						<view class="profit-item flexWrap" v-for="(item,index) in day_platform_commission_list"
							:key="index">
							<view>{{item.report_date}}</view>
							<view>{{item.money}}</view>
						</view>
						<!-- <view class="line"></view>
						<view class="profit-item flexWrap">
							<view>剩余补扣团单系统服务费</view>
							<view>{{operatingData.remaining_platform_commission||'0.00'}}</view>
						</view> -->
					</view>
				</view>
				<view class="describe-model" v-if="describeFlag">
					<image src="/static/user/close.png" class="close-btn" @tap="describeFlag=false"></image>
					<view class="describe-top">
						报表说明
					</view>
					<view class="describe-cont">
						<view class="describe-title">总数据说明：</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							已结算订单数：已支付的小程序订单数（含充值抵扣订单数）+已核销的团单订单数
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							总收入：小程序收入+团单收入的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							已结算金额：小程序收入-小程序退款-小程序系统服务费-银行手续费-今日补扣团单系统服务费
						</view>
					</view>
					<view class="describe-cont">
						<view class="describe-title">小程序收入说明：</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							小程序收入：微信支付开台+门店卡充值+通卡抵扣开台+助教订单的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							微信支付开台：通过微信支付开台订单已支付的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							门店卡充值：门店卡充值订单的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							助教订单：助教订单已支付的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							通卡抵扣开台：通过通卡抵扣开台订单已完成的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							小程序系统服务费：（小程序收入-小程序退款）*3%
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							银行手续费：(微信支付开台+门店卡充值+助教订单)*0.28%+通卡抵扣开台*0.38%，如有退款，会扣除退款金额的手续费
						</view>
					</view>
					<view class="describe-cont">
						<view class="describe-title">团单收入说明：</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							团单收入：美团已核销+抖音已核销的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							美团收入：美团团购开台订单已核销的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							抖音收入：抖音团购开台订单已核销的总收入
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							团单系统服务费（次日补扣）：团单收入*3%，今日的团单系统服务费于次日补扣
						</view>
					</view>
					<view class="describe-cont">
						<view class="describe-title">今日补扣团单系统服务费说明：</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							今日补扣团单系统服务费：今日补扣的团单系统服务费总金额
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							补扣明细：今日补扣的具体月份以及补扣系统服务费金额
						</view>
						<view class="describe-item flexWrapNo">
							<text class="describe-dot"></text>
							剩余待补扣团单系统服务费：截止到当前，剩余的待补扣团单系统服务费总金额
						</view>
					</view>
				</view>
				<view class="mask-wrap" v-if="describeFlag"></view>
				<view class="data-box">
					<view class="data-item" v-for="(item,index) in dataList" :key="index"
						@tap="goOperatingDetails(item)">
						<view class="data-info flexWrap">
							<text>{{item.time}}</text>
							<text>{{item.tatal_income}}</text>
						</view>
						<view class="progress-box">
							<view class="progress-child" :style="{width:item.progress}"></view>
						</view>
					</view>
				</view>
				<h-watermark :title="watermarkTitle" :mobile="watermarkMobile" :appNameShow="false"></h-watermark>

				<!--操作指引悬浮按钮 -->
				<guideline :path="'pages/index/operatingData'"></guideline>
			</view>
		</template>
	</view>
</template>

<script>
	import tools from '../common/lib/tools'
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			const starDate = this.getDate('start', 'day')
			const watermarkTitle = uni.getStorageSync('username')
			const watermarkMobile = uni.getStorageSync('mobile')
			return {
				pageOpc: 0,
				currmentIndex: 0,
				dataList: [],
				operatingData: {
					yjz: 0,
					order_ze: 0,
					cz_sum: 0,
					yhjqk: 0,
					ye_sum: 0,
					meituan_sum: 0
				},
				day_platform_commission_list: [],
				starTime: "",
				endTime: "",
				date: currentDate,
				dateFlag: false,
				fields: 'day',
				watermarkTitle: watermarkTitle,
				watermarkMobile: watermarkMobile,
				dividend_date: "",
				dividend_by:"",
				cooperation_period:"",
				startViewTime: "",
				endViewTime: "",
				screenShow: true,
				in_coming: 0,
				coming_time: "",
				yesdayComing: "",
				comingTimeDay:"",
				describeFlag: false,
				customHeight: {
					height: 30,
					top: 20
				},
				store_type: true,
				isShowChange:false,
				isSevenDay:false,//判断是否是七天前的数据
				identity:1
			}
		},
		onLoad() {
			this.customHeight = wx.getMenuButtonBoundingClientRect()
			this.in_coming =  0
			this.coming_time =''
			this.dividend_date = uni.getStorageSync('dividend_date') || ''
			this.cooperation_period=uni.getStorageSync('cooperation_period') || ''
			this.identity=uni.getStorageSync('identity')||1
			console.log(this.identity)
			this.startViewTime = this.dividend_date || '2022-01-01'
			this.endViewTime=uni.getStorageSync('dividend_by') || ''
			if (this.dividend_date) {
				if (this.areDatesEqual(this.dividend_date)) {
					this.screenShow = true
					let starTime = this.getDate('start', 'day')
					this.starTime = this.daysBetween(this.startViewTime, starTime) < 6 ? this.startViewTime : starTime
					this.endTime = this.getDate('', 'day')
					if(this.cooperation_period==2){
						if(this.isDividend()){
							this.starTime=this.$tools.formatDate(this.subtractOneDay(this.endViewTime,6), 'day')
							this.date=this.endViewTime
							this.endTime=this.endViewTime
						}
					}
				} else {
					this.screenShow = false
				}
			} else {
				this.starTime = this.getDate('start', 'day')
				this.endTime = this.getDate('', 'day')
			}
			if (this.coming_time) {
				let newDate = new Date().getTime() //当前时间戳
				let startDate=Date.parse(this.getDate('start', 'day').replace(/-/g, '/'))
				this.isSevenDay=startDate<this.coming_time* 1000
				if(!this.isSameDay(newDate,this.coming_time* 1000)){
					this.isShowChange=true
					this.store_type=true
					this.yesdayComing = this.$tools.formatDate(this.subtractOneDay(this.coming_time * 1000),'day') //定已旧报表的结束时间
					this.comingTimeDay = this.$tools.formatDate(this.coming_time, 'day') //把进件时间转为日期格式
					if (this.store_type) { //如果新商户
						if (newDate > this.coming_time * 1000) { //如果当前时间大于进件时间
							// 所选日期开始范围
							console.log("newDate > this.coming_time * 1000")
							this.startViewTime = this.comingTimeDay
							this.starTime = this.isSevenDay?this.comingTimeDay:this.getDate('start', 'day') //正常获取开始日期
							if(this.isDividend()){
								this.starTime=this.$tools.formatDate(this.subtractOneDay(this.endViewTime,6), 'day')
								this.date=this.endViewTime
								this.endTime=this.endViewTime
								if(this.convertDateToTimestamp(this.endViewTime.replace(/-/g, '/'))<this.coming_time * 1000){
									this.store_type=false
									this.isShowChange=false
									this.startViewTime = this.dividend_date
								}
							}else{
								console.log('没有到期')
								console.log(this.convertDateToTimestamp(this.dividend_date.replace(/-/g, '/'))>this.coming_time * 1000)
								if(this.convertDateToTimestamp(this.dividend_date.replace(/-/g, '/'))>this.coming_time * 1000){
									this.isShowChange=false
									this.startViewTime = this.dividend_date
								}
							}
						}
					} 
				}
			}
			this.getBusinessStatement();
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		methods: {
			// 如果到期
			isDividend(){
				this.endViewTime=uni.getStorageSync('dividend_by')
				let endViewTime=this.convertDateToTimestamp(this.endViewTime.replace(/-/g, '/'));
				let date = new Date().getTime()
				return endViewTime<=date
			},
			convertDateToTimestamp(dateString) {
			    return new Date(dateString).getTime();
			},
			isSameDay(timestamp1, timestamp2) {
			  const date1 = new Date(timestamp1);
			  const date2 = new Date(timestamp2);
			  return (
			    date1.getFullYear() === date2.getFullYear() &&
			    date1.getMonth() === date2.getMonth() &&
			    date1.getDate() === date2.getDate()
			  );
			},
			changeModel() {
				let starTime=Date.parse(this.starTime.replace(/-/g, '/'))
				let endTime=Date.parse(this.endTime.replace(/-/g, '/'))
				if(this.currmentIndex==1){
					starTime=Date.parse(this.getFirstDayOfMonth(this.$tools.formatMonth(starTime)).replace(/-/g, '/'))
					endTime=Date.parse(this.getLastDayOfMonth(this.$tools.formatMonth(endTime)).replace(/-/g, '/'))
					console.log(this.getLastDayOfMonth(this.$tools.formatMonth(endTime)))
				}
				if (this.store_type) {//如果是新报表切换到旧报表
					this.starTime = this.currmentIndex == 0 ? this.yesdayComing : this.getDate('start', 'month')
					this.startViewTime = '2022-01-01'
					this.date = this.currmentIndex == 0 ? this.yesdayComing : this.getDate('', 'month')
					this.endTime = this.currmentIndex == 0 ? this.yesdayComing : this.getDate('', 'month')
					if(this.coming_time * 1000<=starTime){
						this.starTime = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.yesdayComing)
						this.startViewTime = this.dividend_date?this.dividend_date:'2022-01-01'
						this.date = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.yesdayComing)
						this.endTime =this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.yesdayComing)
					}else{
						this.starTime = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.coming_time)
						this.startViewTime = this.dividend_date?this.dividend_date:'2022-01-01'
						this.date = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.coming_time)
						this.endTime =this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.coming_time)
					}
				} else {
					if(this.currmentIndex == 0){
						this.starTime = this.isSevenDay?this.comingTimeDay:this.getDate('start', 'day') //正常获取开始日期
					}else{
						this.starTime = this.isSevenDay?this.$tools.formatMonth(this.comingTimeDay):this.getDate('start', 'month')//正常获取开始日期
					}
					this.startViewTime = this.$tools.formatDate(this.coming_time, 'day');
					this.date = this.currmentIndex == 0 ? this.getDate({format: true}) : this.getDate('', 'month')
					this.endTime = this.currmentIndex == 0 ? this.getDate({format: true}) : this.getDate('', 'month')
				}
				if(this.cooperation_period==2&&this.identity!=1){
					if(this.isDividend()){
						if(this.convertDateToTimestamp(this.endViewTime.replace(/-/g, '/'))<this.convertDateToTimestamp(this.starTime.replace(/-/g, '/'))){
							this.starTime=this.$tools.formatDate(this.subtractOneDay(this.endViewTime,6), 'day')
							this.starTime=this.currmentIndex==0?this.starTime:this.$tools.formatMonth(Date.parse(this.starTime.replace(/-/g, '/')))
							this.date=this.currmentIndex==0?this.endViewTime:this.$tools.formatMonth(Date.parse(this.endViewTime.replace(/-/g, '/')))
							this.endTime=this.currmentIndex==0?this.endViewTime:this.$tools.formatMonth(Date.parse(this.endViewTime.replace(/-/g, '/')))
						}
					}
				}
				this.store_type = !this.store_type
				this.getBusinessStatement();
			},
			daysBetween(date1, date2) {
				const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
				const firstTime = new Date(date1).getTime();
				const secondTime = new Date(date2).getTime();
				return Math.round((secondTime - firstTime) / oneDay);
			},
			isTimestampBetween(timestamp, startTimestamp, endTimestamp) {
				const date = new Date(timestamp);
				const startDate = new Date(startTimestamp);
				const endDate = new Date(endTimestamp);
				return date.getTime() > startDate.getTime() && date.getTime() < endDate.getTime();
			},
			// 如果当前时间大于购买微股东时间
			areDatesEqual(date) {
				return new Date().getTime() >= new Date(date).getTime();
			},
			// 获取时间
			getDate(type, fields) {
				const date = new Date();
				date.setDate(date.getDate() - 1);
				if (type == 'start' && fields == 'day') { //粒度为天
					date.setDate(date.getDate() - 6);
				}
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type == 'start' && fields == 'year') { //粒度为年
					if (year != 2022) {
						year = year - 1
					}
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				let result = ``
				if (fields == 'month') {
					result = `${year}-${month}`
				} else if (fields == 'year') {
					result = `${year}`
				} else {
					result = `${year}-${month}-${day}`
				}
				return result;
			},
			subtractOneDay(timestamp,day) {
				day=day||1
				const date = new Date(timestamp);
				date.setDate(date.getDate() - day);
				return date.getTime();
			},
			// 选择时间
			bindDateChange(e) {
				console.log(e.target.value)
				let index = e.currentTarget.dataset.index
				if (index == 0) {
					this.starTime = e.target.value
				} else {
					this.endTime = e.target.value
				}
			},
			isup() {
				let coming_time = this.$tools.formatDate(this.subtractOneDay(this.coming_time * 1000), 'day')
				let startTime = this.currmentIndex == 1 ? this.getFirstDayOfMonth(this.starTime) : this.starTime;
				let endTime = this.currmentIndex == 1 ? this.getLastDayOfMonth(this.endTime) : this.endTime;
				let isup = this.isTimestampBetween(this.coming_time * 1000, Date.parse(startTime.replace(/-/g, '/')), Date
					.parse(endTime.replace(/-/g, '/')))
				return isup;
			},
			// 重置
			reSet() {
				this.starTime = this.getDate('start')
				this.endTime = this.getDate({
					format: true
				})
			},
			// 提交
			submit() {
				this.getBusinessStatement();
				this.closeDate();
			},
			showDate() {
				this.dateFlag = !this.dateFlag
			},
			closeDate() {
				this.dateFlag = false
			},
			getFirstDayOfMonth(yearMonth) {
				const date = new Date(yearMonth);
				date.setDate(1); // 设置日为1，即该月的第一天
				return date.toISOString().split('T')[0]; // 返回YYYY-MM-DD格式的字符串
			},
			getLastDayOfMonth(yearMonth) {
				const date = new Date(yearMonth + '-01'); // 创建当月的第一天
				date.setMonth(date.getMonth() + 1, 0); // 设置月份和日期为下个月的第0天，即当前月的最后一天
				date.setDate(date.getDate());
				return date.toISOString().split('T')[0]; // 返回最后一天的日
			},
			changeNav(index) {
				this.currmentIndex = index
				if (this.currmentIndex == 0) {
					this.fields = 'day'
				} else if (this.currmentIndex == 1) {
					this.fields = 'month'
				}
				if(!this.coming_time||!this.isShowChange){
					if(this.cooperation_period==2&&this.identity!=1){
						if(this.isDividend()){
							console.log('进来了')
							this.starTime=this.$tools.formatDate(this.subtractOneDay(this.endViewTime,6), 'day')
							this.starTime=this.currmentIndex==0?this.starTime:this.$tools.formatMonth(Date.parse(this.starTime.replace(/-/g, '/')))
							this.date=this.currmentIndex==0?this.endViewTime:this.$tools.formatMonth(Date.parse(this.endViewTime.replace(/-/g, '/')))
							this.endTime=this.currmentIndex==0?this.endViewTime:this.$tools.formatMonth(Date.parse(this.endViewTime.replace(/-/g, '/')))
						}else{
							this.starTime = this.getDate('start',this.fields)
							this.endTime = this.getDate('', this.fields)
						}
					}else{
						this.starTime = this.getDate('start',this.fields)
						this.endTime = this.getDate('', this.fields)
					}
					this.getBusinessStatement();
					return;
				}
				uni.setStorageSync('type',this.fields)
				let starTime=Date.parse(this.starTime.replace(/-/g, '/'))
				let endTime=Date.parse(this.endTime.replace(/-/g, '/'))
				if(this.currmentIndex==1){
					starTime=Date.parse(this.getFirstDayOfMonth(this.$tools.formatMonth(starTime)).replace(/-/g, '/'))
					endTime=Date.parse(this.getLastDayOfMonth(this.$tools.formatMonth(endTime)).replace(/-/g, '/'))
				}
				if (!this.store_type) {
					console.log("!this.store_type")
					this.starTime = this.currmentIndex == 0 ? this.yesdayComing : this.getDate('start', 'month')
					this.startViewTime = '2022-01-01'
					this.date = this.currmentIndex == 0 ? this.yesdayComing : this.getDate('', 'month')
					this.endTime = this.currmentIndex == 0 ? this.yesdayComing : this.getDate('', 'month')
					if(this.coming_time * 1000<endTime){
						console.log(this.coming_time * 1000<endTime)
						this.starTime = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(endTime)
						this.startViewTime = this.dividend_date?this.dividend_date:'2022-01-01'
						this.date = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(endTime)
						this.endTime =this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(endTime)
					}else{
						this.starTime = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.yesdayComing)
						this.startViewTime = this.dividend_date?this.dividend_date:'2022-01-01'
						this.date = this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.yesdayComing)
						this.endTime =this.currmentIndex == 0 ? this.yesdayComing :this.$tools.formatMonth(this.yesdayComing)
					}
				} else {
					if(this.currmentIndex == 0){
						this.starTime = this.isSevenDay?this.comingTimeDay:this.getDate('start', 'day') //正常获取开始日期
					}else{
						this.starTime = this.isSevenDay?this.$tools.formatMonth(this.comingTimeDay):this.getDate('start', 'month')//正常获取开始日期
					}
					this.startViewTime = this.$tools.formatDate(this.coming_time, 'day');
					this.date = this.currmentIndex == 0 ? this.getDate({format: true}) : this.getDate('', 'month')
					this.endTime = this.currmentIndex == 0 ? this.getDate({format: true}) : this.getDate('', 'month')
				}
				if(this.cooperation_period==2&&this.identity!=1){
					if(this.isDividend()){
						console.log('进来了')
						if(this.convertDateToTimestamp(this.endViewTime.replace(/-/g, '/'))<this.convertDateToTimestamp(this.starTime.replace(/-/g, '/'))){
							this.starTime=this.$tools.formatDate(this.subtractOneDay(this.endViewTime,6), 'day')
							this.starTime=this.currmentIndex==0?this.starTime:this.$tools.formatMonth(Date.parse(this.starTime.replace(/-/g, '/')))
							this.date=this.currmentIndex==0?this.endViewTime:this.$tools.formatMonth(Date.parse(this.endViewTime.replace(/-/g, '/')))
							this.endTime=this.currmentIndex==0?this.endViewTime:this.$tools.formatMonth(Date.parse(this.endViewTime.replace(/-/g, '/')))
						}
					}
				}
				this.getBusinessStatement();
			},
			// 营业报表
			getBusinessStatement() {
				let startTime = this.currmentIndex == 1 ? this.getFirstDayOfMonth(this.starTime) : this.starTime;
				let endTime = this.currmentIndex == 1 ? this.getLastDayOfMonth(this.endTime) : this.endTime;
				let isup = this.isTimestampBetween(this.coming_time * 1000, Date.parse(startTime.replace(/-/g, '/')), Date
					.parse(endTime.replace(/-/g, '/')))
				console.log(isup)
				this.$request.post(this.$api.businessStatement, {
					store_id: uni.getStorageSync('store_id'),
					start_time: this.starTime,
					end_time: this.endTime,
					type: this.fields,
					coming_time: isup ? this.coming_time : '',
					store_type: this.store_type?2:1
				}, {
					token: true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						this.operatingData = data.statistics
						this.day_platform_commission_list = this.operatingData.day_platform_commission_list
						this.dataList = data.list
						for (let i in this.dataList) {
							this.dataList[i].progress = Number(this.dataList[i].tatal_income / 800) * 100 + '%'
						}
					}
				})
			},
			goOperatingDetails(operatingInfo) {
				operatingInfo.store_type = this.store_type
				uni.setStorageSync('operatingInfo', operatingInfo)
				uni.navigateTo({
					url: '/page-home/operatingDetails'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: 50upx;
	}

	.content {
		padding: 0 36upx;
	}

	.triangle {
		border-top-color: #FFFFFF;
	}

	.change-box {
		font-size: 28upx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		width: 233upx;
		background: rgba(0, 0, 0, 0.06);
		border: 2px solid rgba(255, 255, 255, 0.251);
		border-radius: 63upx;
		justify-content: center;
		z-index: 999;

		.change-icon {
			width: 36upx;
			height: 36upx;
			margin-left: 24upx;
		}
	}

	.top-box {
		.screen-box {
			.date-box {
				margin-top: 32upx;
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 500;
				line-height: 60upx;
				color: #FFFFFF;

				.calendar-icon {
					width: 48upx;
					height: 48upx;
					margin-right: 24upx;
				}
			}

			.nav-box {
				.nav-item {
					width: 80upx;
					height: 60upx;
					line-height: 60upx;
					text-align: center;
					background: #1D1C5C;
					border-radius: 16upx;
					font-size: 32upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					margin-right: 20upx;
				}

				.active {
					background-color: #26BCFD;
				}
			}
		}

		.memberData-img {
			width: 228upx;
			height: 228upx;
		}
	}

	.profit-box {
		// height: 684upx;
		background: #fff;
		border-radius: 16upx;
		padding: 0 30upx;

		.profit-top {
			font-size: 48upx;
			font-family: PingFang SC;
			font-weight: bold;
			line-height: 66upx;
			color: #040336;
			padding-top: 36upx;
			padding-bottom: 46upx;
			border-bottom: 2upx solid #DDDDDD;

			.profit-text {
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 34upx;
				color: #666666;
				margin-top: 8upx;
			}
		}

		.profit-cont {
			flex-wrap: wrap;
			margin-top: 34upx;

			.profit-item {
				font-size: 46upx;
				font-family: PingFang SC;
				font-weight: bold;
				line-height: 66upx;
				color: #040336;
				width: 33%;
				margin-bottom: 44upx;
				position: relative;

				.look {
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 500;
					line-height: 40upx;
					color: #5FD4FF;
					text-align: center;
					position: absolute;
					bottom: -30upx;
				}

				.profit-text {
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 400;
					line-height: 34upx;
					color: #666666;
					margin-top: 8upx;
				}
			}
		}
	}

	.profit-box-new {
		.start-time {
			font-size: 25upx;
			color: #fdd143;
		}

		.describe-box {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: rgba(255, 255, 255, 0.5);
			line-height: 33rpx;
			justify-content: flex-end;

			.describe-icon {
				width: 32upx;
				height: 32upx;
				margin-right: 6upx;
			}
		}

		.profit-top {
			margin-top: 20upx;

			.profit-item {
				width: 222rpx;
				height: 128rpx;
				background: #1D1C5C;
				border-radius: 12rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 800;
				font-size: 40rpx;
				color: #FFFFFF;
				line-height: 47rpx;
				justify-content: center;

				.profit-text {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: rgba(255, 255, 255, 0.5);
					line-height: 28rpx;
					text-align: center;
					font-style: normal;
					text-transform: none;
					margin-top: 10upx;
				}
			}
		}

		.profit-cont {
			background: #1D1C5C;
			border-radius: 12rpx;
			padding: 28upx;
			margin-top: 14upx;

			.profit-title-box {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #26BCFD;
				line-height: 38rpx;
				font-style: normal;
				text-transform: none;
				margin-bottom: 24upx;
				align-items: baseline;
			}

			.profit-title-right {
				align-items: flex-end;

				.look {
					font-size: 24upx;
				}
			}

			.profit-item {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: rgba(255, 255, 255, 0.8);
				line-height: 50rpx;
			}

			.line {
				width: 100%;
				height: 1rpx;
				background: rgba(255, 255, 255, 0.1);
				margin: 10upx 0;
			}
		}

		.profit-month {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 38rpx;
			padding: 38upx 28upx;
			background: #1D1C5C;
			border-radius: 12rpx;
			margin-top: 14upx;
		}
	}

	.data-box {
		margin-top: 40upx;

		.data-item {
			margin-top: 20upx;

			.data-info {
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 60upx;
				color: #FFFFFF;
			}

			.progress-box {
				height: 20upx;
				background: #36355E;
				border-radius: 20upx;

				.progress-child {
					height: 20upx;
					background: #26BCFD;
					border-radius: 20upx;
					width: 100%;
					max-width: 100%;
				}
			}
		}
	}

	.date-boxs {
		padding: 30rpx;
		z-index: 999;
		border-bottom: 1rpx solid rgba(71, 73, 84, .5);
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		background-color: #040336;

		.date-title {
			font-size: 30rpx;
			font-family: PingFang;
			font-weight: 500;
			color: #FFFFFF;
			margin-bottom: 26rpx;
		}

		.date-cont {
			.screen-item {
				width: 250rpx;
				height: 66rpx;
				line-height: 66rpx;
				text-align: center;
				border: 1rpx solid #26BCFD;
				color: #323232;
				font-size: 28rpx;
				border-radius: 6rpx;
				padding: 0 30rpx;

				.select-input {
					font-size: 26rpx;
					font-family: PingFang;
					font-weight: 400;
					color: #26BCFD;
				}

				picker {
					width: 100%;
					text-align: left;
				}
			}
		}

		.determine-btn {
			margin-top: 40rpx;
			justify-content: center;

			view {
				width: 230rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 26rpx;
				font-family: PingFang;
				font-weight: 500;
				color: #26BCFD;
				border: 1rpx solid #26BCFD;
				border-radius: 20rpx;
				margin-right: 30upx;
			}

			.determine {
				background: #26BCFD;
				color: #FFFFFF;
				border: none;
			}
		}
	}

	.mask-wrap {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		margin: auto;
		z-index: 99;
		background: rgba(4, 3, 54, 0.8);
	}

	.describe-model {
		background: #1D1C5C;
		border-radius: 12rpx;
		z-index: 999;
		position: fixed;
		top: 100upx;
		left: 28upx;
		right: 28upx;
		margin: auto;
		padding: 40upx 28upx;
		height: 1134upx;
		overflow-y: scroll;

		.describe-top {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 34rpx;
			color: #FFFFFF;
			line-height: 40rpx;
			text-align: center;
		}

		.close-btn {
			width: 40upx;
			height: 40upx;
			position: absolute;
			top: 40upx;
			right: 28upx;
		}

		.describe-cont {
			.describe-title {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #26BCFD;
				line-height: 35rpx;
				margin-bottom: 14upx;
			}

			.describe-item {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: rgba(255, 255, 255, 0.8);
				line-height: 48rpx;
				margin-bottom: 14upx;
				align-items: baseline;

				.describe-dot {
					display: inline-block;
					width: 10upx;
					height: 10upx;
					border-radius: 50%;
					background-color: #D2D2DE;
					flex: none;
					margin-right: 10upx;
				}
			}
		}
	}
</style>